package cn.edu.zafu.bigdata.XuShuXin.Exp1029;

/*作业3 ： 相等性判断*/
public class CubeXsx {
    public static void main(String[] args) {
        CubeXsx cb1 = new CubeXsx(5, 10.2, 6);
        CubeXsx cb2 = new CubeXsx(5, 10.2, 6);
        CubeXsx cb3 = new CubeXsx(5.1, 10.2, 6);

        System.out.println(cb1.equals(cb2) ? "相等" : "不相等");
        System.out.println(cb1.equals(cb3) ? "相等" : "不相等");
        System.out.println(cb2.equals(cb3) ? "相等" : "不相等");

    }

    private double length;

    private double width;

    private double height;

    //equals


    @Override
    public boolean equals(Object obj) {
        //判断是否为同一类型
        if (this == obj) return true;
        //判断为空  是否为cube类型
        if (obj == null || getClass() != obj.getClass()) return false;

        CubeXsx cube = (CubeXsx) obj;

        return Double.compare(cube.getHeight(), height) == 0 &&
                Double.compare(cube.getLength(), length) == 0 &&
                Double.compare(cube.getWidth(), width) == 0;

    }

    //构造方法

    public CubeXsx() {
    }

    public CubeXsx(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }
    //set and get
    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }

}
